#ifndef _APP_CHARGER_H_
#define _APP_CHARGER_H_
#include <stdint.h>
#include "hal_adc.h"
#include "hal_gpio.h"
#include "hal_pwm.h"
#include "hal_flash.h"
#include "hal_tim.h"
#include "t_pid.h"
#include "app_main.h"


#define  CURRENT_ADDRESS             220*1024
#define  VOLTAGE_ADDRESS             CURRENT_ADDRESS + 4

#define  CONFIG_ADC_NUM              5      //adc通道个数
#define  IO_ADC_TEMP                 pa6    //温度检测引脚
#define  IO_ADC_24V                  pa5    //降压检测引脚
#define  IO_ADC_BAT                  pa4    //电压检测引脚
#define  IO_ADC_CURRENT              pa3    //电流检测引脚
#define  IO_ADC_80V                  pa2    //输入电压检测引脚

#define  IO_LED1                     pb8    //绿灯   充电中闪烁   充电完成点亮
#define  IO_LED2                     pb9    //蓝灯   空载

#define  IO_IDC                      pa13    //快充检测引脚

#define  RESISTANCE                  5310   //40度时候的温度
#define  ALARM_TEMP                  (3300 * RESISTANCE / (RESISTANCE + 10000))
#define  SAVE_RESISTANCE             6520   //35度时候的温度
#define  SAFE_TEMP                   (3300 * SAVE_RESISTANCE / (SAVE_RESISTANCE + 10000))

#define  CHARGE_ERR                  0X08    //充电错误
#define  TEMP_ERR                    0X04    //温度过高错误
#define  CONFIG_V_ERR                0X02    //电压设置错误
#define  CONFIG_I_ERR                0X01    //电流设置错误

enum ADC_POSITION {
    ADC_TEMP = 0,
    ADC_CURRENT = 1,
    ADC_BAT = 2,
    ADC_80V = 3,
    ADC_24V = 4
};

enum LED_STATE {
    NO_LOADER = 0,
    CHARGING = 1,
    CHARGE_FULL = 2,
};

struct led_type {
    struct gpio_type *blueled;
    struct gpio_type *greenled;
    struct gtim_type *tim;
    uint8_t state;
};

void app_charger_init(void);
void app_charger_loop(void);
void app_charger_adjust(void);
void app_24v_adjust(void);
int tonum(uint8_t *data);
#endif